Framework
Physical representation of connected player.
Player
s are a type of Entity
. They are a physical representation of a Character
- and can possess at most one Character
object at a time that you can interface with.
See the Garry's Mod Wiki for all other methods that the Player
class has.
Functions
playerMeta:HasPrivilege(privilegeName)
Checks if the player has a specified CAMI privilege.
Parameters
-
privilegeName
String
The name of the privilege to check.
Returns
-
Boolean
True if the player has the privilege, false otherwise.
Example Usage
if player:HasPrivilege("admin") then
print("Player is an admin.")
end
playerMeta:Name()
Returns this player's current name.
Returns
-
String
Name of this player's currently loaded character
-
String
Steam name of this player if the player has no character loaded
Example Usage
print("Player Name:", player:Name())
playerMeta:PlaySound(sound, volume, pitch, shouldEmit)
Plays a sound for the player.
Parameters
-
sound
String
The sound to play.
-
volume
Integer
default: 75
The volume of the sound.
-
pitch
Integer
default: 100
The pitch of the sound.
-
shouldEmit
Boolean
Whether to emit sound server-side or send it to the client.
Example Usage
player:PlaySound("ambient/alarms/warningbell1.wav", 100, 100, false)
playerMeta:addMoney(amount)
Adds money to the player's character. This function uses Lilia methods to add the specified amount of money to the player. It is designed to be compatible with the DarkRP addMoney method. If the total amount exceeds the configured money limit, the excess is spawned as an item in the world.
Parameters
-
amount
Integer
The amount of money to add.
Example Usage
player:addMoney(1000, {player}, false)
playerMeta:binaryQuestion(question, option1, option2, manualDismiss, callback)
Requests a binary choice from the player.
Parameters
-
question
String
The question to present to the player.
-
option1
String
The text for the first option.
-
option2
String
The text for the second option.
-
manualDismiss
Boolean
Whether the notice should be manually dismissed.
-
callback
Function
The function to call with the choice (0 or 1) when the player selects an option.
Example Usage
player:binaryQuestion("Confirm Action", "Yes", "No", false, function(choice)
if choice == 0 then
print("Player chose Yes.")
else
print("Player chose No.")
end
end)
playerMeta:canAfford(amount)
Checks if the player's character can afford a specified amount of money. This function uses Lilia methods to determine if the player can afford the specified amount. It is designed to be compatible with the DarkRP canAfford method.
Parameters
-
amount
Integer
The amount of money to check.
Returns
-
Boolean
Whether the player's character can afford the specified amount of money.
Example Usage
if player:canAfford(500) then
print("Player can afford the item.")
else
print("Player cannot afford the item.")
end
playerMeta:chatNotify(message)
Displays a notification for this player in the chatbox.
Parameters
-
message
String
Text to display in the notification.
Example Usage
player:chatNotify("Welcome to the server!")
playerMeta:chatNotify(message)
Notifies the player with a message.
Parameters
-
message
String
The message to notify the player.
Example Usage
player:chatNotify("Welcome to the server!")
playerMeta:chatNotifyLocalized(message, any)
Displays a notification for the player in the chatbox with the given language phrase.
Parameters
-
message
String
ID of the phrase to display to the player.
-
any
...
Arguments to pass to the phrase.
Example Usage
player:chatNotifyLocalized("welcome_message", player:Nick())
playerMeta:chatNotifyLocalized(message, any)
Notifies the player with a localized message.
Parameters
-
message
String
ID of the phrase to display to the player.
-
any
...
Arguments to pass to the phrase.
Example Usage
player:chatNotifyLocalized("welcome_message", player:Nick())
playerMeta:createRagdoll(freeze)
Creates a ragdoll entity for the player.
Parameters
-
freeze
Boolean
Whether to freeze the ragdoll initially.
Returns
-
Entity
The created ragdoll entity.
Example Usage
local ragdoll = player:createRagdoll(true)
playerMeta:createServerRagdoll(dontSetPlayer)
Creates a ragdoll entity for the player on the server.
Parameters
-
dontSetPlayer
Boolean
Determines whether to associate the player with the ragdoll.
Returns
-
Entity
The created ragdoll entity.
Example Usage
local ragdoll = player:createServerRagdoll()
playerMeta:distanceFromEnt(entity)
Calculates the distance from the player to the specified entity.
Parameters
-
entity
Entity
The entity to calculate the distance to.
Returns
-
Float
The distance from the player to the entity.
Example Usage
local dist = player:distanceFromEnt(entity)
print("Distance:", dist)
playerMeta:doStaredAction(entity, callback, time, onCancel, distance)
Performs a stared action towards an entity for a certain duration.
Parameters
-
entity
Entity
The entity towards which the player performs the stared action.
-
callback
Function
The function to call when the stared action is completed.
-
time
Integer
default: 5
The duration of the stared action in seconds.
-
onCancel
Function
The function to call if the stared action is canceled.
-
distance
Integer
default: 96
The maximum distance for the stared action.
Example Usage
player:doStaredAction(targetEntity, function()
print("Stared action completed.")
end, 10, function()
print("Stared action canceled.")
end, 150)
playerMeta:entitiesNearPlayer(radius, playerOnly)
Retrieves entities near the player within a specified radius.
Parameters
-
radius
Integer
The radius within which to search for entities.
-
playerOnly
Boolean
If true, only return player entities.
Returns
-
Table
A table containing the entities near the player.
Example Usage
local nearbyPlayers = player:entitiesNearPlayer(200, true)
for _, p in ipairs(nearbyPlayers) do
print("Nearby Player:", p:Nick())
end
playerMeta:getChar()
Returns this player's currently possessed Character
object if it exists.
Returns
-
Character
Currently loaded character
-
nil
If this player has no character loaded
Example Usage
local char = player:getChar()
if char then
print("Character Name:", char:getName())
end
playerMeta:getCurrentVehicle()
Gets the current vehicle the player is in, if any.
Returns
-
Entity or nil
The current vehicle entity, or nil if the player is not in a vehicle.
Example Usage
local vehicle = player:getCurrentVehicle()
if vehicle then
print("Player is in a vehicle:", vehicle:GetClass())
end
playerMeta:getDarkRPVar(var)
Retrieves the player's DarkRP money. This is used as compatibility for DarkRP Vars.
Parameters
-
var
String
The DarkRP variable to fetch (only "money" is allowed).
Returns
-
Integer or nil
The player's money if the variable is valid, or nil if not.
Example Usage
local money = player:getDarkRPVar("money")
if money then
print("Player Money:", money)
end
playerMeta:getEyeEnt(distance)
Retrieves the entity within the player's line of sight.
Parameters
-
distance
Integer
The maximum distance to consider.
Returns
-
Entity or nil
The entity within the player's line of sight, or nil if not found.
Example Usage
local eyeEnt = player:getEyeEnt(200)
if eyeEnt then
print("Entity in sight:", eyeEnt:GetClass())
end
playerMeta:getItemDropPos()
Calculates the position to drop an item from the player's inventory.
Returns
-
Vector
The position to drop an item from the player's inventory.
Example Usage
local dropPos = player:getItemDropPos()
item:spawn(dropPos, Angle(0, 0, 0))
playerMeta:getItemWeapon()
Retrieves the active weapon item of the player.
Returns
-
Entity or nil
The active weapon entity of the player, or nil if not found.
Example Usage
local weapon, item = player:getItemWeapon()
if weapon then
print("Active Weapon:", weapon:GetClass())
end
playerMeta:getItems()
Retrieves the items of the player's character inventory.
Returns
-
Table or nil
A table containing the items in the player's character inventory, or nil if not found.
Example Usage
local items = player:getItems()
if items then
for _, item in ipairs(items) do
print("Item:", item.uniqueID)
end
end
playerMeta:getLiliaData(key, default)
Retrieves a value from the player's Lilia data.
Parameters
-
key
String
The key for the data.
-
default
any[opt=nil]
The default value to return if the key does not exist.
Returns
-
any
The value corresponding to the key, or the default value if the key does not exist.
Example Usage
local level = player:getLiliaData("level", 1)
print("Player Level:", level)
playerMeta:getLiliaData(key, default)
Retrieves a value from the local Lilia data.
Parameters
-
key
String
The key for the data.
-
default
any[opt=nil]
The default value to return if the key does not exist.
Returns
-
any
The value corresponding to the key, or the default value if the key does not exist.
Example Usage
local rank = player:getLiliaData("rank", "Novice")
print("Player Rank:", rank)
playerMeta:getMoney()
Retrieves the amount of money owned by the player's character.
Returns
-
Integer
The amount of money owned by the player's character.
Example Usage
local money = player:getMoney()
print("Player Money:", money)
playerMeta:getPlayTime()
Retrieves the player's total playtime.
Returns
-
Float
The total playtime of the player.
Example Usage
local playTime = player:getPlayTime()
print("Playtime:", playTime, "seconds")
playerMeta:getPlayTime()
Retrieves the player's total playtime.
Returns
-
Float
The total playtime of the player.
Example Usage
local playTime = player:getPlayTime()
print("Playtime:", playTime, "seconds")
playerMeta:getPlayTime()
Retrieves the player's total playtime.
Returns
-
Float
The total playtime of the player.
Example Usage
local playTime = player:getPlayTime()
print("Playtime:", playTime, "seconds")
playerMeta:getRagdoll()
Returns the player's ragdoll entity if valid.
Returns
-
Entity or nil
The player's ragdoll entity if it exists and is valid, otherwise nil.
Example Usage
local ragdoll = player:getRagdoll()
if ragdoll then
print("Ragdoll found:", ragdoll:GetClass())
end
playerMeta:getTrace()
Performs a trace from the player's view.
Returns
-
Table
A table containing the trace result.
Example Usage
local trace = player:getTrace()
if trace.Hit then
print("Trace hit:", trace.Entity:GetClass())
end
playerMeta:getTracedEntity()
Retrieves the entity traced by the player's aim.
Returns
-
Entity or nil
The entity traced by the player's aim, or nil if not found.
Example Usage
local target = player:getTracedEntity()
if target then
print("Traced Entity:", target:GetClass())
end
playerMeta:hasRagdoll()
Checks if the player has a valid ragdoll entity.
Returns
-
Boolean
Whether the player has a valid ragdoll entity.
Example Usage
if player:hasRagdoll() then
print("Player has a ragdoll.")
end
playerMeta:hasValidVehicle()
Checks if the player is in a valid vehicle.
Returns
-
Boolean
True if the player is in a valid vehicle, false otherwise.
Example Usage
if player:hasValidVehicle() then
print("Player is in a valid vehicle.")
end
playerMeta:isFemale()
Checks if the player's character is female based on the model.
Returns
-
Boolean
Whether the player's character is female.
Example Usage
if player:isFemale() then
print("Player character is female.")
end
playerMeta:isMoving()
Checks if the player is currently moving.
Returns
-
Boolean
Whether the player is currently moving.
Example Usage
if player:isMoving() then
print("Player is moving.")
end
playerMeta:isNearPlayer(radius, entity)
Checks if the player is near another entity within a specified radius.
Parameters
-
radius
Integer
The radius within which to check for proximity.
-
entity
Entity
The entity to check proximity to.
Returns
-
Boolean
Whether the player is near the specified entity within the given radius.
Example Usage
if player:isNearPlayer(100, targetPlayer) then
print("Player is near the target.")
end
playerMeta:isNoClipping()
Checks if the player is currently in noclip mode.
Returns
-
Boolean
Whether the player is in noclip mode.
Example Usage
if player:isNoClipping() then
print("Player is in noclip mode.")
end
playerMeta:isObserving()
Checks if the player is currently observing.
Returns
-
Boolean
Whether the player is currently observing.
Example Usage
if player:isObserving() then
print("Player is observing.")
end
playerMeta:isOutside()
Checks if the player is currently outside (in the sky).
Returns
-
Boolean
Whether the player is currently outside (in the sky).
Example Usage
if player:isOutside() then
print("Player is outside.")
end
playerMeta:isRunning()
Checks if the player is running.
Returns
-
Boolean
Whether the player is running.
Example Usage
if player:isRunning() then
print("Player is running.")
end
playerMeta:isStuck()
Checks if the player is stuck.
Returns
-
Boolean
Whether the player is stuck.
Example Usage
if player:isStuck() then
print("Player is stuck.")
end
playerMeta:loadLiliaData(callback)
Loads Lilia data for the player from the database.
Parameters
-
callback
Function
Function to call after the data is loaded, passing the loaded data as an argument.
Example Usage
player:loadLiliaData(function(data)
print("Data loaded:", data)
end)
playerMeta:notify(message)
Notifies the player with a message.
Parameters
-
message
String
The message to notify the player.
playerMeta:notifyLocalized(message, ...)
Notifies the player with a localized message.
Parameters
-
message
String
The key of the localized message to notify the player.
-
...
Table
Additional arguments to format the localized message.
playerMeta:notifyP(text)
Notifies the player with a message and prints the message to their chat.
Parameters
-
text
String
The message to notify and print.
Example Usage
player:notifyP("You have received a new item!")
playerMeta:notifyP(message)
Notifies the player with a message and prints the message to their chat.
Parameters
-
message
String
The message to notify and print.
Example Usage
player:notifyP("You have received a new item!")
playerMeta:openPage(url)
Opens a web page for the player.
Parameters
-
url
String
The URL of the web page to open.
Example Usage
player:openPage("https://example.com")
playerMeta:openUI(panel)
Opens a VGUI panel for the player.
Parameters
-
panel
String
The name of the VGUI panel to open.
Example Usage
player:openUI("InventoryPanel")
playerMeta:openUI(panel)
Opens a UI panel for the player.
Parameters
-
panel
String
The panel type to create.
Returns
-
Panel
The created UI panel.
Example Usage
local inventoryPanel = player:openUI("InventoryPanel")
playerMeta:requestDropdown(title, subTitle, options, callback)
Requests a dropdown selection from the player.
Parameters
-
title
String
The title of the request.
-
subTitle
String
The subtitle of the request.
-
options
Table
The table of options to choose from.
-
callback
Function
The function to call upon receiving the selected option.
Example Usage
player:requestDropdown("Choose Option", "Select one of the following:", {"Option1", "Option2"}, function(selected)
print("Player selected:", selected)
end)
playerMeta:requestOptions(title, subTitle, options, limit, callback)
Requests multiple options selection from the player.
Parameters
-
title
String
The title of the request.
-
subTitle
String
The subtitle of the request.
-
options
Table
The table of options to choose from.
-
limit
Integer
The maximum number of selectable options.
-
callback
Function
The function to call upon receiving the selected options.
Example Usage
player:requestOptions("Select Items", "Choose up to 3 items:", {"Item1", "Item2", "Item3"}, 3, function(selected)
print("Player selected:", table.concat(selected, ", "))
end)
playerMeta:requestString(title, subTitle, callback, default)
Requests a string input from the player.
Parameters
-
title
String
The title of the string input dialog.
-
subTitle
String
The subtitle or description of the string input dialog.
-
callback
Function
The function to call with the entered string.
-
default
String
default: nil
The default value for the string input.
Returns
-
Promise or nil
A promise object resolving with the entered string, or nil if a callback is provided.
Example Usage
player:requestString("Enter Name", "Please enter your name:", function(name)
print("Player entered:", name)
end)
Using promise
local promise = player:requestString("Enter Name", "Please enter your name:", "DefaultName")
if promise then
promise:next(function(name)
print("Player entered:", name)
end)
end
playerMeta:saveLiliaData()
Saves the player's Lilia data to the database.
Example Usage
player:saveLiliaData()
playerMeta:setAction(text, time, callback, startTime, finishTime)
Sets an action bar for the player.
Parameters
-
text
String
The text to display on the action bar.
-
time
Integer
default: 5
The duration for the action bar to display in seconds. Set to 0 or nil to remove the action bar immediately.
-
callback
Function
Function to execute when the action bar timer expires.
-
startTime
Integer
optional
The start time of the action bar, defaults to the current time.
-
finishTime
Integer
optional
The finish time of the action bar, defaults to startTime + time.
Example Usage
player:setAction("Processing...", 10, function(p) print("Action completed for", p:Nick()) end)
playerMeta:setLiliaData(key, value, noNetworking)
Sets a key-value pair in the player's Lilia data.
This method updates the player's liaData
table with the specified key and value. Optionally, it can suppress the networking of the data update.
Parameters
-
key
String
The key for the data.
-
value
any[opt=nil]
The value to set for the specified key. Defaults to
nil
if not provided.
-
noNetworking
Boolean[opt=false]
If set to
true
, the data update will not be sent to clients. Defaults tofalse
.
Returns
-
void
Example Usage
```lua
Example 1: Setting a key-value pair with networking
player:setLiliaData("score", 1500)
Example 2: Setting a key-value pair without networking
player:setLiliaData("health", 100, true)
```
playerMeta:setLocalVar(key, value)
Sets a local variable for the player.
Parameters
-
key
String
The key of the variable.
-
value
any
The value of the variable.
Example Usage
player:setLocalVar("health", 100)
playerMeta:setRagdoll(entity)
Sets the player's ragdoll entity.
Parameters
-
entity
Entity
The entity to set as the player's ragdoll.
Example Usage
local ragdoll = player:createServerRagdoll()
player:setRagdoll(ragdoll)
playerMeta:setRagdolled(state, time, getUpGrace, getUpMessage)
Sets the player to a ragdolled state or removes the ragdoll.
Parameters
-
state
Boolean
Whether to set the player to a ragdolled state (
true
) or remove the ragdoll (false
).
-
time
Integer
default: 0
The duration for which the player remains ragdolled.
-
getUpGrace
Integer
default: 0
The grace period for the player to get up before the ragdoll is removed.
-
getUpMessage
String
default: "@wakingUp"
The message displayed when the player is getting up.
Example Usage
player:setRagdolled(true, 10, 5, "@gettingUp")
playerMeta:setWeighPoint(name, vector, onReach)
Sets a waypoint for the player.
Parameters
-
name
String
The name of the waypoint.
-
vector
Vector
The position vector of the waypoint.
-
onReach
Function
Function to call when the player reaches the waypoint.
Example Usage
player:setWeighPoint("Spawn Point", Vector(100, 200, 300), function(p)
print("Player reached the waypoint.")
end)
playerMeta:setWeighPoint(name, vector, onReach)
Sets a waypoint for the player.
Parameters
-
name
String
The name of the waypoint.
-
vector
Vector
The position vector of the waypoint.
-
onReach
Function
Function to call when the player reaches the waypoint.
Example Usage
player:setWeighPoint("Spawn Point", Vector(100, 200, 300), function(p)
print("Player reached the waypoint.")
end)
playerMeta:squaredDistanceFromEnt(entity)
Calculates the squared distance from the player to the specified entity.
Parameters
-
entity
Entity
The entity to calculate the distance to.
Returns
-
Float
The squared distance from the player to the entity.
Example Usage
local sqDist = player:squaredDistanceFromEnt(entity)
print("Squared Distance:", sqDist)
playerMeta:stopAction()
Stops the action bar for the player. Removes the action bar currently being displayed.
Example Usage
player:stopAction()
playerMeta:syncVars()
Synchronizes networked variables with the player.
Example Usage
player:syncVars()
playerMeta:takeMoney(amount)
Takes money from the player's character.
Parameters
-
amount
Integer
The amount of money to take.
Example Usage
player:takeMoney(200)